package cn.tedu.home1ess.admin.content.dao.repository.impl;

import cn.tedu.common.web.PageDataVO;
import cn.tedu.home1ess.admin.content.dao.mapper.VerificationDetailMapper;
import cn.tedu.home1ess.admin.content.dao.repository.IVerificationDetailRepository;
import cn.tedu.home1ess.admin.content.pojo.param.PictureParam;
import cn.tedu.home1ess.admin.content.pojo.po.VerificationDetailPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class VerificationDetailRepositoryImpl implements IVerificationDetailRepository {

    @Autowired
    private VerificationDetailMapper verificationDetailMapper;
    @Override
    public PageDataVO<VerificationDetailPO> pageOrderByUserAdminId(Integer pageSize, Integer currentPage) {
        QueryWrapper queryWrapper=new QueryWrapper();
        //todo 需要改id，从token中拿
        queryWrapper.eq("user_admin_id",2);
        PageHelper.startPage(currentPage,pageSize);
        List list = verificationDetailMapper.selectList(queryWrapper);
        PageInfo<VerificationDetailPO> pageInfo = new PageInfo<>(list);
        PageDataVO<VerificationDetailPO> result = new PageDataVO<>();
        BeanUtils.copyProperties(pageInfo,result);
        return result;
    }

    @Override
    public void addPicture(Long id, String houseImg) {
        VerificationDetailPO verificationDetailPO = new VerificationDetailPO();
        verificationDetailPO.setHouseImg(houseImg);
        UpdateWrapper updateWrapper=new UpdateWrapper();
        updateWrapper.eq("id",id);
        verificationDetailMapper.update(verificationDetailPO,updateWrapper);
    }

    @Override
    public VerificationDetailPO selectPOById(Long id) {

        return verificationDetailMapper.selectById(id);
    }

    @Override
    public void deletePictureById(Long id) {
        UpdateWrapper<VerificationDetailPO> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", id).set("house_img", null);
        verificationDetailMapper.update(null, updateWrapper);
    }


}
